<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.setTimeout()
        //直接写函数
        setTimeout(function() {
                console.log('时间到了');
                alert('时间到啦')
            }, 2000)
            //调用函数写函数名
        setTimeout(fn, 4000)

        function fn() {
            console.log('4秒到了');
        }
        //2.setInterval()
        setInterval(function() {
            console.log('2秒到了');
        }, 2000)
    </script>
</body>

</html>